USE [Musicman]
GO
/****** Object:  StoredProcedure [dbo].[AddPendingDownload]    Script Date: 11/15/2008 22:59:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeleteUser]
	@PersonID bigint
AS
BEGIN
 BEGIN TRANSACTION 	
		
	DELETE FROM  MUSICMAN.DBO.USERDOWNLOADS WHERE UserID = @PersonID
	DELETE FROM  MUSICMAN.DBO.USERS WHERE Personid = @PersonID
 
 COMMIT

END


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[DeleteUser]
	@PersonID bigint
AS
BEGIN
BEGIN TRANSACTION;
BEGIN TRY
		
	DELETE FROM  MUSICMAN.DBO.USERDOWNLOADS WHERE UserID = @PersonID
	DELETE FROM  MUSICMAN.DBO.USERROLES WHERE UserID = @PersonID
	DELETE FROM  MUSICMAN.DBO.USERS WHERE Personid = @PersonID

COMMIT TRANSACTION;
END TRY
BEGIN CATCH
	ROLLBACK TRANSACTION;

    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

    SELECT @ErrorMessage = ERROR_MESSAGE();
    SELECT @ErrorSeverity = ERROR_SEVERITY();
    SELECT @ErrorState = ERROR_STATE();
	RAISERROR (@ErrorMessage, -- Message text.
                   @ErrorSeverity, -- Severity.
                   @ErrorState -- State.
                   );
END CATCH

END


